import React, { useState, useEffect } from 'react'
import styles from './index.module.css'
import { useSelector } from 'react-redux'
import { useNavigate } from 'react-router-dom'
import http from '../../utils/http'
function Index() {
    const { start, end, date } = useSelector((state) => state.CitySlice)
    const [list, setList] = useState([])
    const navigate = useNavigate()

    const getList = async () => {
        const res = await http.post('/api/trip/train', {
            start,
            end,
            date
        })

        console.log(res);

        const { code, data } = res.data

        if (code === 200) {
            setList(data)
        }

    }

    useEffect(() => {
        getList()
    }, [])

    const handlelDetail = (item) => {
        navigate(`/detail`, { state: item })
    }
    return (
        <div>
            {
                list?.map((item, ind) => (
                    <div key={ind} className={styles.box_wroe} onClick={() => handlelDetail(item)}>
                        <div className={styles.left_wroe}>
                            <span>{item.start}</span>
                            <span>{item.startTime}</span>
                            <span>{item.end}</span>
                            <span>商务票<b>有票</b></span>
                            <span>一等票<b>有票</b></span>
                            <span>二等票<b>有票</b></span>
                        </div>
                        <div className={styles.right_wroe}>
                            <span>￥{item.tick?.vip}</span>
                        </div>
                    </div>
                ))
            }
        </div>
    )
}

export default Index
